<?php
namespace app\supply;


use app\common\Common;


class Supply extends Base{
    //供货商列表
    public function supply_business($page=1,$pre=5){
        $b = ($page-1)*$pre;
        $business = Common::db_count("user_id,proxy_name,address,portrait_phone","","drh_proxy_shop_info limit ".$b.",".$pre);
        return json(['code'=>$this->t_code,'msg'=>"ok",'data'=>$business]);
    }
    //供货商商品详情
    public function supply_goods(int $shop_id,$page=1,$pre=3){
        $goods_assortment = Common::db_count("id,Channel_commodity_id","","drh_proxy_classification","account_id=".$shop_id);
        foreach ($goods_assortment as $k=>$v){
            print_r(1);
        }
       // $date = implode(",",Common::er_array($data));
        // echo "<pre>";
        // print_r($data);
        exit;
        // $b = ($page-1)*$pre;
        // $good = Common::db_count("*","","drh_proxy_ware","id IN(".$date.") limit ".$b.",".$pre);
        // $repeat = Common::db_count("goods_id","","drh_goods_proxy","goods_id IN(".$date.")");
        // foreach ($good as $k=>$v){
        //     if(!empty($repeat[$k]['goods_id']) == $v['id']){
        //         $good[$k]['repeat']= 1;
        //     }else{
        //         $good[$k]['repeat']= 0;
        //     }
        //     $good[$k]['json'] = unserialize($v['json']);
        // }
        //return json(['code'=>$this->t_code,'msg'=>"ok",'data'=>$good]);
    }
    //商户代理商品
    public function agent(int $shop_id,int $goods_id,int $proportion,int $proxy_shop_id){
        $repeat = Common::db_count("COUNT(id)","`count`","drh_goods_proxy","shop_id=".$shop_id." AND goods_id=".$goods_id)[0]["count"]??0;
        if($repeat>=1){
            return json(['code'=>$this->f_code,"msg"=>"您已代理该商品"]);
        }
            $data = [
                'shop_id'=>$shop_id,
                'goods_id'=>$goods_id,
                'proportion'=>$proportion,
                'proxy_shop_id'=>$proxy_shop_id,
                'create_time'=>time()
            ];
            $agent = Common::db_insert("drh_goods_proxy",$data);
            if($agent){
                return json(['code'=>$this->t_code,"msg"=>"ok"]);
            }
                return json(['code'=>$this->f_code,"msg"=>"代理无效"]);
    }
    //交子参数详情
    public function parameter(){
        return json(['code'=>$this->t_code,"msg"=>"ok",'data'=>unserialize(Common::db_count("copulation","","drh_parameter")[0]['copulation'])]);
    }
}